import Vue from "vue";
import Vuex from "vuex";
import {
    lampTypeDropDown
 } from '@/api/lampController'
 import {
    userListCopy
} from '@/api/userController'
import createVuexAlong from 'vuex-along'

Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        permissionList: [], //权限路由
        factoryInfo: {},
        isOutLogin: false,
        hasAuth: true,
        codeDistinguish: '', //区分停用还是编辑权限code
        lampTypeDownList:[],
        userList:[],
        account:'',
        page: 1,
        router: null,
        tab: null
    },
    actions: {
        //联络灯类型下拉
        lampTypeDropDownFn:async function(context,params){
            const res = await lampTypeDropDown(params)
            if (res.code == 200) {
                context.commit('setLampTypeDownList', res.data)
            }
        },
        //用户下拉
        userListFn:async function(context,params){
            const res = await userListCopy(params)
            if (res.code == 200) {
                context.commit('setUserList', res.data)
            }
        },
    },
    mutations: {
        setPermissionList(state, payload) {
            state.permissionList = payload
        },
        setFactoryInfo(state, payload) {
            state.factoryInfo = payload
        },
        setIsOutLogin(state, payload) {
            state.isOutLogin = payload
        },
        setCodeDistinguish(state, payload) {
            state.codeDistinguish = payload
        },
        setAuth(state, payload) {
            state.hasAuth = payload
        },
        setLampTypeDownList(state, payload) {
            state.lampTypeDownList = payload
        },
        setUserList(state, payload) {
            state.userList = payload
        },
        setAccount(state, payload) {
            state.account = payload
        },
        setPage(state, page) {
            state.page = page;
        },
        setRouter(state, router) {
            state.router = router;
        },
        setTab(state, tab) {
            state.tab = tab;
        }
    },
    getters: {},
    plugins: [createVuexAlong()]
});